package com.yaoli.LianJia;

import java.util.*;

public class Main{
    public static void main(String [] args){
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int array[] = new int[n];
        for(int i = 0 ; i < n ; i++){
            array[i] = input.nextInt();
        }

        int begin = 0;
        int end = n - 1;
        long total = 0;

        int j = 1;
        while(j <= n){
            if(array[begin] < array[end]){
                total = total + j * array[begin];
                begin++;
            }else{
                total = total + j * array[end];
                end--;
            }
            j++;
        }

        System.out.println(total);

    }
}
